<!-- 操作组件 -->
<script>
import { formatDateOnly, isSameDate } from "@/utils/index";
import { loginShulan } from "@/api/reviewActivities/userRelevance";

const operationConfig = [
  {
    title: "开通会员",
    filter: ({ rolesName }) => rolesName !== "超级会员",
    method(info, title) {
      this.showOptionPop = true;
      this.operation = title;
      this.currentUserInfo = {
        wxMobile: info.wxMobile,
        mobile: info.mobile,
        nickName: info.nickName,
        realName: info.realName,
        startDate: new Date(),
        endDate: "",
        amount: "",
        memberCode: "supermember",
        memberName: "超级会员",
        voucher: "",
        voucherUrl: "",
        agentId: info.agentId || info.id,
        type: "0",
        operate: "add",
        pushCode: "",
        cardType: "",
      };
    },
  },
  {
    title: "续约会员",
    filter: ({ rolesName }) => rolesName === "超级会员",
    method(info, title) {
      this.showOptionPop = true;
      this.operation = title;
      const d = new Date();
      const memberInfoItem = info.memberInfo[0];
      const endD = new Date(memberInfoItem.endDate);
      let startDate;
      if (d.getTime() > memberInfoItem.endDate && !isSameDate(d, endD)) {
        startDate = d.getTime();
      } else {
        startDate = memberInfoItem.endDate + 1000 * 60 * 60 * 24;
      }

      this.currentUserInfo = {
        wxMobile: info.wxMobile,
        mobile: info.mobile,
        nickName: info.nickName,
        realName: info.realName,
        lastDate: formatDateOnly(memberInfoItem.endDate),
        startDate: new Date(startDate),
        endDate: "",
        memberCode: "supermember",
        memberName: "超级会员",
        voucher: "",
        voucherUrl: "",
        agentId: info.agentId || info.id,
        type: "1",
        operate: "add",
        pushCode: "",
        cardType: "",
      };
    },
  },
  {
    title: "登录后台",
    filter: () => true,
    method(info) {
      loginShulan({
        agentId: info.agentId || info.id,
      }).then(({ data }) => {
        const { isSuccess, successMessage} = data
        if (isSuccess && successMessage) {
          window.open(successMessage, '_blank');
        }
      });
    },
  },
];
export default {
  name: "com-operation",
  props: {
    value: Object,
  },

  methods: {},

  render() {
    const { value } = this;
    return this.$scopedSlots.default({
      operations: operationConfig.filter(({ filter }) => filter(value)),
    });
  },
};
</script>

<style></style>
